home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / newsgroups / misc.20020314-20021006 / 000416_fdc@columbia.edu_Tue Oct 1 15:32:50 EDT 2002.msg < prev    next >
Text File  |  2020-01-01  |  2KB  |  88 lines

  1. Article: 13752 of comp.protocols.kermit.misc
  2. Path: newsmaster.cc.columbia.edu!news.columbia.edu!news-not-for-mail
  3. From: fdc@columbia.edu (Frank da Cruz)
  4. Newsgroups: comp.protocols.kermit.misc
  5. Subject: Re: Return Value from User Defined Function
  6. Date: 1 Oct 2002 15:31:19 -0400
  7. Organization: Columbia University
  8. Lines: 71
  9. Message-ID: <anct67$ns6$1@watsol.cc.columbia.edu>
  10. References: <ancqme$2980$1@msunews.cl.msu.edu>
  11. NNTP-Posting-Host: watsol.cc.columbia.edu
  12. X-Trace: newsmaster.cc.columbia.edu 1033500680 1005 128.59.39.139 (1 Oct 2002 19:31:20 GMT)
  13. X-Complaints-To: postmaster@columbia.edu
  14. NNTP-Posting-Date: 1 Oct 2002 19:31:20 GMT
  15. Xref: newsmaster.cc.columbia.edu comp.protocols.kermit.misc:13752
  16.  
  17. In article <ancqme$2980$1@msunews.cl.msu.edu>,
  18. Robert Gibbens <rgibbens@redskytech.com> wrote:
  19. : How would I go about evaluating the return value from a User defined
  20. : function?
  21. : For example, I have the function
  22. : DEFINE mlChangePassword {
  23. :     (Do something)
  24. :     IF FAILURE {
  25. :         return 1
  26. :     }
  27. :     else
  28. :     {
  29. :         return 0
  30. :     }
  31. : }
  32. If all you want to do is return success or failure, you would use END rather
  33. than RETURN:
  34.  
  35.   DEFINE mlChangePassword {
  36.       (Do something)
  37.       IF FAILURE {
  38.           end 1
  39.       } else {
  40.           end 0
  41.       }
  42.   }
  43.  
  44. Then you can test the macro invocation with IF SUCCESS / FAILURE:
  45.  
  46.   mlChangePassword someargs...
  47.   if fail exit 1 "Password change failed"
  48.  
  49. If you want a macro to return an arbitrary value, rather than just succeed
  50. or fail, use the RETURN statement.  The return value can be a number, a
  51. string, whatever.  The caller can access the RETURN value in the \v(return)
  52. variable.
  53.  
  54. You can also access a macro's return value directly if you invoke it as
  55. a user-defined function:
  56.  
  57.   .somevariable := \fexecute(macroname args)
  58.  
  59. For example:
  60.  
  61.   define addemup {
  62.       local \%i \%s
  63.       .\%s := 0
  64.       for \%i 1 \v(argc)-1 1 {
  65.           increment \%s \&_[\%i]
  66.       }
  67.       return \%s
  68.   }
  69.   .sum = \fexecute(addemup 1 2 3 4)
  70.   echo \m(sum)
  71.  
  72. which prints:
  73.  
  74.   10
  75.  
  76. The script language is documented in "Using C-Kermit":
  77.  
  78.   http://www.columbia.edu/kermit/ck60manual.html
  79.  
  80. as amplified by the update notes for versions 7 and 8:
  81.  
  82.   http://www.columbia.edu/kermit/ckermit70.html
  83.   http://www.columbia.edu/kermit/ckermit80.html
  84.  
  85. - Frank
  86.